package com.zyfdroid.backupftpserver.ftplets;

import android.os.Environment;
import android.util.Log;

import org.apache.ftpserver.ftplet.FtpFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class SdcardRootFtpFile implements FtpFile {
    @Override
    public String getAbsolutePath() {
        return "/sdcard";
    }

    @Override
    public String getName() {
        return "sdcard";
    }

    @Override
    public boolean isHidden() {
        return false;
    }

    @Override
    public boolean isDirectory() {
        return true;
    }

    @Override
    public boolean isFile() {
        return false;
    }

    @Override
    public boolean doesExist() {
        return true;
    }

    @Override
    public boolean isReadable() {
        return true;
    }

    @Override
    public boolean isWritable() {
        return false;
    }

    @Override
    public boolean isRemovable() {
        return false;
    }

    @Override
    public String getOwnerName() {
        return "user";
    }

    @Override
    public String getGroupName() {
        return "user";
    }

    @Override
    public int getLinkCount() {
        return 1;
    }

    @Override
    public long getLastModified() {
        return 0;
    }

    @Override
    public boolean setLastModified(long l) {
        return false;
    }

    @Override
    public long getSize() {
        return 0;
    }

    @Override
    public Object getPhysicalFile() {
        return null;
    }

    @Override
    public boolean mkdir() {
        return false;
    }

    @Override
    public boolean delete() {
        return false;
    }

    @Override
    public boolean move(FtpFile ftpFile) {
        return false;
    }
    File file = (Environment.getExternalStorageDirectory());
    @Override
    public List<? extends FtpFile> listFiles() {
        ArrayList<SdcardFtpFile> fff = new ArrayList<>();
        File[] fs = file.listFiles();
        Log.e("List of sdcard dir",file.getAbsolutePath());
        for (File f : fs) {
            fff.add(new SdcardFtpFile(file,f.getAbsolutePath().substring(file.getAbsolutePath().length())));
        }
        return fff;
    }

    @Override
    public OutputStream createOutputStream(long l) throws IOException {
        throw  new IOException("👴是目录");
    }

    @Override
    public InputStream createInputStream(long l) throws IOException {
        throw  new IOException("👴是目录");
    }
}
